package com.test.config;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import com.test.eventbus.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;

@Configuration
public class EventBusConfig {

    @Bean
    public EventBus getEventBus() {
        AsyncEventBus eventBus = new AsyncEventBus(
                Executors.newFixedThreadPool(20),
                new SubscriberExceptionHandlerImpl()
        );
        return eventBus;
    }

    @Bean
    public BizTask bizTask(EventBus eventBus) {
        return new BizTask(eventBus);
    }

    @Bean
    public FirstSubScriber firstSubScriber(BizTask bizTask) {
        FirstSubScriber firstSubScriber = new FirstSubScriber();
        firstSubScriber.setBizTask(bizTask);
        return firstSubScriber;
    }

    @Bean
    public Object reg(EventBus eventBus, FirstSubScriber firstSubScriber) {
        eventBus.register(firstSubScriber);
//        eventBus.register(new SecondSubscriber());
        return new Object();
    }
}
